﻿ 
using SHKF.B2C.Model.Entity.WorkingCenter;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace SHKF.B2C.BLL.WorkingCenter
{
    /// <summary>
    /// ERP门店映射
    /// </summary>
   public  class ShopRelatedBLL : WorkingCenterBLL
    {
        public ShopRelatedBLL(SqlSugarClient db) : base(db)
        {
            
        }

        /// <summary>
        /// 通过分仓SN获取数据,就得保证分仓唯一
        /// </summary>
        /// <param name="WarehousSN"></param>
        /// <returns></returns>
        public ShopRelatedEntity Query(string WarehousSN)
        {
            ShopRelatedEntity info =this.db
                .Queryable<ShopRelatedEntity>()
                .Where(ww => ww.WarehousSN == WarehousSN)
                .First();

            return info;
        }

        public List<ShopRelatedEntity> QueryList(int ShopVSN)
        {
            List < ShopRelatedEntity > list = this.db
                .Queryable<ShopRelatedEntity>()
                .Where(ww => ww.ShopVSN == ShopVSN)
                .OrderBy(it=>it.OrderNumber)
                .ToList();

            return list;
        }

        public ShopRelatedEntity Save(ShopRelatedEntity info)
        {
            if (info.SN == 0)
            {
                info.SN = this.db.Insertable<ShopRelatedEntity>(info)
                    .ExecuteReturnBigIdentity();
            }
            else
            {
                this.db
                    .Updateable<ShopRelatedEntity>(info)
                    .ExecuteCommand();
            }
            return info;
        }

        public int Delete(long SN)
        {
           int result = this.db.Deleteable<ShopRelatedEntity>().In(SN)
                .ExecuteCommand();

            return result;
        }
 
    }
}
